﻿using System.Reflection;

namespace CoreEx.DynamicInvoker
{
    /// <summary>
    /// A generic delegate that is used to execute dynamic methods.
    /// </summary>
    /// <param name="target">The target for witch to invoke the delegate.</param>
    /// <param name="parameters"></param>
    /// <returns></returns>
    public delegate object MethodHandler(object target, object[] parameters);
    
    /// <summary>
    /// Represents a dynamic method factory that is capable of creating a delegate for any type of <see cref="MemberInfo"/>
    /// </summary>
    /// <typeparam name="TMember">The type of member </typeparam>
    public interface IDynamicFactory<TMember> where TMember : MemberInfo
    {
        /// <summary>
        /// Creates a <see cref="MethodHandler"/> delegate needed to invoke the <paramref name="targetMember"/>.
        /// </summary>
        /// <param name="targetMember"></param>
        /// <returns></returns>
        MethodHandler CreateDelegate(TMember targetMember);
    }
}
